package sg.edu.nus.iss.billing.service.subscription;

import java.util.Iterator;
import java.util.List;

import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.dao.subscription.SubscriptionDAO;
import sg.edu.nus.iss.billing.vo.subscription.CableTvVO;
import sg.edu.nus.iss.billing.vo.subscription.SubscriptionVO;

public class CableTV extends SubscriptionImpl {
	
	//Add CableTV Business Logic here

	public boolean canTerminate(String accountNo) {
		
		boolean result= true;
		SubscriptionDAO subscriptionDAO = new SubscriptionDAO();
		
		List<SubscriptionVO> subscribedPlanList=  subscriptionDAO.getSubscriptionForAcct(accountNo);
		for(Iterator<SubscriptionVO> subscribed = subscribedPlanList.iterator(); subscribed.hasNext(); ) {
			//Subscription Main Plan
			 SubscriptionVO subscribedPlan = subscribed.next();
		
	         if(subscribedPlan instanceof CableTvVO)
	         {
	        	 CableTvVO cableTVVO = (CableTvVO)subscribedPlan;
	        	 if(cableTVVO.getStatus().equals(Util.ACCOUNT_STATUS_ACTIVE))
	        	 {	
	        		 //If start date if after the today date - 6 months
	        		 if(cableTVVO.getStartDate().compareTo(Util.dateAddMonth(Util.getSystemDate(), -6))>0)
	        		 {
	        			 result = false;
	        			 break;
	        		 }
	        	 }
	         }
	         
		}
		
		return result;
	}
}
